package com.wjv.example.spbt.mybatis.config;

import com.wjv.example.spbt.mybatis.mapper.MyIntercepts;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


import javax.sql.DataSource;

/**
 * <p>Title: MyBatisConfig</p>
 *
 * @author wjv
 * @date 2021/4/12 12:15
 * @description
 */
@Configuration
public class MyBatisConfig {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private MyIntercepts myIntercepts;

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setDataSource(this.dataSource);
        factoryBean.setPlugins(myIntercepts);

        return factoryBean.getObject();
    }
}
